<template>

  <div>
    <!-- 11111 -->
    <!-- {{ dataContent.orderNum }} -->
    <p>
      拣货单单号： <span style="margin-right: 40px;">{{ dataContent.orderNum }}</span>
      生成时间 <span style="margin-right: 40px;">{{ dataContent.createTime }}</span>
      拣货完成时间 <span style="margin-right: 40px;">{{ dataContent.completeTime }}</span>
      拣货人 <span style="margin-right: 40px;">{{ dataContent.lastPickPerson }}</span>
      <!-- <el-button link type="primary" size="small" @click.prevent="Printorderpicking">
        打印拣货单
      </el-button> -->
    </p>
    <div class="table">
      <el-table :data="dataContent.detailList" style="width: 1500px" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" />
        <el-table-column label="子订单号" width="180">
          <template #default="scope">{{ scope.row.orderOid }}</template>
        </el-table-column>
        <el-table-column label="SKU信息" width="220">
          <template #default="scope">{{ scope.row.orderSkuPropertiesName }}</template>
        </el-table-column>
        <el-table-column label="快递单号" width="220">
          <template #default="scope">{{ scope.row.orderInvoiceNo }}</template>
        </el-table-column>
        <el-table-column label="拣货数量" width="220">
          <template #default="scope">{{ scope.row.orderNum }}</template>
        </el-table-column>
        <el-table-column label="拣货库位" width="220">
          <template #default="scope">{{ scope.row.warehouseLocationName }}</template>
        </el-table-column>
        <el-table-column label="拣货时间" width="220">
          <template #default="scope">{{ scope.row.pickTime }}</template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <el-button link type="primary" size="small" @click.prevent="PrintExpressReceipt(scope.row.id)">
              重新打快递面单
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script setup>
import { ref, onBeforeMount, onMounted, onBeforeUnmount } from 'vue'
// import { ElMessage } from 'element-plus'
import { useAlertsStore } from '@/store/index'

import { useRoute } from 'vue-router'
import { getPrePickOrderDetail, getPrePickOrderDetailPrePickOrder, prePickOrderSinglePrintExpressOrder } from '@/api/index'
const store = useAlertsStore()

onMounted(() => {
  doConnect()
})
const route = useRoute()
const ids = ref('')
const dataContent = ref('')
onBeforeMount(() => {
  ids.value = route.query.id
  if (route.query.name === '详情') {
    getPrePickOrderDetailPrePickOrderbtns()
  } else if (route.query.name === '打印') {
    getList()
  }
})
const datas = ref('')
const getList = () => {
  getPrePickOrderDetail({ id: ids.value }).then(res => {
    const { data: { data } } = res
    console.log('data')
    dataContent.value = data
    console.log(dataContent.value.orderNum)
    datas.value = data
  })
}
const getPrePickOrderDetailPrePickOrderbtns = () => {
  getPrePickOrderDetailPrePickOrder({ id: ids.value }).then(res => {
    const { data: { data } } = res
    console.log('data')
    dataContent.value = data
    console.log(dataContent.value.orderNum)
    datas.value = data
  })
}
const PrintExpressReceipt = (row) => {
  // prePickOrderSinglePrintExpressOrder({ id: row.id }).then(res => {
  //   console.log(res)
  //   const val = { cmd: 'print', requestID: '123458976', version: '1.0', task: { taskID: (new Date().getTime() + ''), preview: false, printer: '', notifyMode: 'allInOne', previewType: 'pdf', documents: [{ documentID: '0123456789', contents: [{ data: { width: '45', height: '35', padding: '2', barcodeHeight: '13', barcodeMargin: '1.8', fontSize: '8', showOrderName: '0', left: '2', waybillCode: row.orderInvoiceNo, skuInfo: row.orderSkuPropertiesName }, templateURL: 'http://yitaoweb.sc.kuaidi600.com/moban/yto.frx' }] }] } }
  //   store.socket.send(JSON.stringify(val))
  // })

  prePickOrderSinglePrintExpressOrder({
    id: row
  }).then(res => {
    const { data: { data } } = res
    console.log(data)
    const lists = JSON.parse(localStorage.getItem('PrinterSetList'))
    const val = { cmd: 'print', requestID: '123458976', version: '1.0', task: { taskID: (new Date().getTime() + ''), preview: false, printer: lists[0].PrinterList, notifyMode: 'allInOne', previewType: 'pdf', documents: [{ documentID: '0123456789', contents: [JSON.parse(data)] }] } }
    store.socket.send(JSON.stringify(val))
  })
}
// // 拣货
// const Printorderpicking = (row) => {
//   // console.log('1111111')
//   if (localStorage.getItem('PrinterSetListJH')) {
//     const lists = JSON.parse(localStorage.getItem('PrinterSetListJH'))
//     // console.log(lists[0].PrinterList)
//     const val = { cmd: 'print', requestID: '123458976', version: '1.0', task: { taskID: (new Date().getTime() + ''), preview: false, printer: lists[0].PrinterList, notifyMode: 'allInOne', previewType: 'pdf', documents: [{ documentID: '0123456789', contents: [{ data: { width: '210', height: '297', padding: '2', fontSize: '8', left: '2', skuInfo: dataContent.value, barcodeHeight: '13' }, templateURL: 'http://yitaoweb.sc.kuaidi600.com/moban/A4JH.xml' }] }] } }
//     store.socket.send(JSON.stringify(val))
//   } else {
//     ElMessage.error('先设置打印机')
//   }
// }
const doConnect = () => {
  console.log('d打开了不')
  store.socket = new WebSocket('ws://localhost:13528')
  // 打开Socket
  store.socket.onopen = function (event) {
    // 监听消息
    store.socket.onmessage = function (event) {
      // localStorage.setItem('printerproperties', event.data)
    }
    // 监听Socket的关闭
    store.socket.onclose = function (event) {
      // console.log('Client notified socket has closed', event)
    }
  }
}
// 销毁
onBeforeUnmount(() => {
  console.log('销毁')
  store.destroyed()
})

</script>

<style lang='less' scoped></style>
